package com.jhc.drone.communication.processor;


import com.jhc.drone.communication.enums.ProtocolEnum;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lcp
 * @date 2025年01月2025/1/7 10:08
 * @describe
 */
@Slf4j
public class PackUnpackMessageProcessor implements MessageProcessor {

    private final PackMessageProcessor packMessageHandler;

    private final UnpackMessageProcessor unpackMessageHandler;

    public PackUnpackMessageProcessor(ProtocolEnum protocolEnum) {
        this.packMessageHandler = new PackMessageProcessor(protocolEnum);
        this.unpackMessageHandler = new UnpackMessageProcessor(protocolEnum);
    }

    @Override
    public byte[] pack(Object data) {
        log.debug("Packing data");
        return packMessageHandler.pack(data);
    }

    @Override
    public void unpack(ByteBuf data, Channel channel) {
        //log.debug("Unpacking data {} ",channel.isOpen());
        unpackMessageHandler.unpack(data,channel);
    }

    @Override
    public void send(byte[] data, String sn) {
        log.info("sending ....{}",sn);
    }

    @Override
    public void sendBySysId(byte[] data, Integer sysId) {
        log.info("sendBySysId ....{}",sysId);
    }
}
